package com.example.administrator.myapplication;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.myapplication.fragment.NewsListFragment;
import com.example.administrator.myapplication.fragment.NewslistFragment2;
import com.example.administrator.myapplication.fragment.NewslistFragment3;
import com.example.administrator.myapplication.fragment.NewslistFragment4;

public class MainActivity extends AppCompatActivity {

    private TextView textView1;
    private TextView textView2;
    private TextView textView3;
    private TextView textView4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }
    private void initView(){
        textView1 = findViewById(R.id.fragment1);
        textView2 = findViewById(R.id.fragment2);
        textView3 = findViewById(R.id.fragment3);
        textView4 = findViewById(R.id.fragment4);


    }
    private void initData(){


    }
    private void initEvent(){

        textView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NewsListFragment newsListFragment = new NewsListFragment();//实例化fragment对象
                //提交事务
                getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newsListFragment).commit();
            }
        });
        textView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NewslistFragment2 newsListFragment2 = new NewslistFragment2();//实例化fragment对象
                getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newsListFragment2).commit();
            }
        });
        textView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NewslistFragment3 newsListFragment3 = new NewslistFragment3();//实例化fragment对象
               getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newsListFragment3).commit();
            }
        });
        textView4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              NewslistFragment4 newsListFragment4 = new NewslistFragment4();//实例化fragment对象
                getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newsListFragment4).commit();
            }
        });
    }
}
